package com.help10000.rms.ui.activitys

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.amir.common.beans.GatheringInfoData
import com.amir.common.beans.RepairInfo
import com.amir.common.utils.ButtonUtils
import com.amir.common.utils.HideUtil
import com.amir.common.utils.MoneyEdiTextUtil
import com.amir.common.utils.ToastUtil
import com.amir.common.weight.DuplicateClickProxy
import com.help10000.rms.R
import com.help10000.rms.mvp.presenter.GatheringPresenter
import com.help10000.rms.mvp.view.GatheringView
import com.help10000.rms.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_gathering.*

/**
 * 收款
 */
class CashEntryActivity : BaseActivity<GatheringPresenter, GatheringView>(), View.OnClickListener,
    GatheringView {
    var repairInfo: RepairInfo? = null
    override fun getlayoutId(): Int {
        return R.layout.activity_gathering
    }

    override fun initView() {
        MoneyEdiTextUtil.afterDotTwo(et_money)
        et_money.requestFocus()
        HideUtil.openKeyboard(this, et_money)
    }

    override fun initData(savedInstanceState: Bundle?) {
        repairInfo = intent.getSerializableExtra("data") as RepairInfo
        mPresenter.gathingData(repairInfo?.ID)

    }

    override fun initListener() {
        btn_next.setOnClickListener(DuplicateClickProxy(this))
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btn_next -> {
                if (!ButtonUtils.isFastDoubleClick(v.id)) {
                    val money = et_money.text.trim().toString()
                    if (money.isEmpty() || money.toFloat() == 0f) {
                        ToastUtil.show("请输入金额")
                        return;
                    }
                    HideUtil.closeKeyboard(this)
                    val intent = Intent(mContext, CashCodeActivity::class.java)
                    intent.putExtra("money", money.toFloat())
                    intent.putExtra("RepairId", repairInfo?.ID)
                    startActivity(intent)
                }
            }
        }
    }

    override fun createPresenter(): GatheringPresenter {
        return GatheringPresenter(this)
    }

    override fun infoSuccess(data: GatheringInfoData) {
//        tv_nameTel.text = "${repairInfo?.CustName}  ${repairInfo?.Tel}"
//        tv_address.text = " ${repairInfo?.ProvName}${repairInfo?.CityName}${repairInfo?.TownName}${repairInfo?.Zone5}
        //  tv_nameTel.text = "${data?.CustName}"
        tv_address.text = " ${data?.Addr}"
        et_money.setText(data?.ServCharge)
    }
}